package comu.hnevc.zh.testdemo.dao;

import android.content.Context;

import com.j256.ormlite.dao.Dao;

import java.sql.SQLException;
import java.util.List;

public class RechargeDao {
    private Context context;
    private Dao<RechargeBean, Integer> dao;

    public RechargeDao(Context context) {
        this.context = context;
        try {
            this.dao = DatabaseHelper.getInstance(context).getDao(RechargeBean.class);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    //增加数据
    public void insert(RechargeBean data) {
        try {
            dao.create(data);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }


    //删除数据
    public void delete(RechargeBean data) {
        try {
            dao.delete(data);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }


    //修改数据
    public void update(RechargeBean data) {
        try {
            dao.update(data);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    //通过ID查询一条数据
    public RechargeBean queryById(int id){
       RechargeBean rechargeBean=null;
        try {
            rechargeBean=dao.queryForId(id);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return rechargeBean;
    }

    //通过所有数据
    public List<RechargeBean> queryByAll(){
        List<RechargeBean> rechargeBeans =null;
        try {
            rechargeBeans=dao.queryForAll();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return rechargeBeans;
    }
}
